﻿using Orchard;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Whatsnexx.Models;

namespace Whatsnexx.Drivers
{
    public class WhatsnexxPartDriver : ContentPartDriver<WhatsnexxPart>
    {
        private readonly IOrchardServices _services;

        public WhatsnexxPartDriver(IOrchardServices services) 
        {
            _services = services;
        }

        protected override string Prefix
        {
            get
            {
                return "Whatsnexx";
            }
        }

      
        //GET - When building the form
        protected override DriverResult Editor(WhatsnexxPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Whatsnexx_Edit", () =>
                                                           shapeHelper.EditorTemplate(TemplateName: "Parts/Whatsnexx",
                                                                                      Model: part,
                                                                                      Prefix: Prefix));
        }

        //POST - When submitting 
        protected override DriverResult Editor(WhatsnexxPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
        {
            //IUpdateModel updater is the controller which handled the POST
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}
